import java.util.ArrayList;
import java.util.List;

import static java.util.Arrays.asList;

/**
 * Created with IntelliJ IDEA.
 * User: Thoughtworker
 * Date: 8/21/13
 * Time: 1:39 PM
 * To change this template use File | Settings | File Templates.
 */
public class Calculator {
    public int Add(String input) {
        List<String> numbers = Delimit(input, ",");
        List<String> delimitedNumbers = SecondDelimiter(numbers, "\n");
        int sum = 0;
        for (int i = 0; i < delimitedNumbers.size(); i++) {
            sum += Integer.parseInt(delimitedNumbers.get(i));
        }
        return sum;
    }

    public List<String> Delimit(String numbers, String delimiter) {
        return asList(numbers.split(delimiter));
    }

    public List<String> SecondDelimiter(List<String> delimitedFirst, String secondDelimiter) {
        List<List> lists = new ArrayList<List>();
        for (int i = 0; i < delimitedFirst.size(); i++) {
            lists.add(Delimit(delimitedFirst.get(i), secondDelimiter));
        }
        List<String> delimitedSecond = new ArrayList<String>();
        for (int i = 0; i < lists.size(); i++) {
            delimitedSecond.addAll(lists.get(i));
        }
        return delimitedSecond;
    }
}
